package cn.com.dhcc.ddi.task.dao;

import cn.com.dhcc.app.core.dao.BaseDao;
import cn.com.dhcc.app.core.exception.DaoException;
import cn.com.dhcc.ddi.task.vo.TableLog;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 交换数据表日志Dao
 * @日期：201611/16 11:44
 * @作者：张洪涛
 * @版权所有：东华软件
 * @版本：1.0
 */
@Repository
public class TableLogDao extends BaseDao {
    /**
     * 获取交换表信息
     * @param id 主键
     * @return
     * @throws DaoException
     */
    public TableLog get(String id) throws DaoException {
        return getDao().getModuleById("",TableLog.class,new Object[]{id});
    }


    /**
     * 新增
     * @par task
     * @return
     * @throws DaoException
     */
    public int insert(TableLog obj) throws DaoException {
        return getDao().insertModule("新增",obj);
    }

    /**
     * 修改
     * @param task
     * @return
     * @throws DaoException
     */
    public int update(TableLog obj) throws DaoException {
        return getDao().updateModuleByIdExecuteNull("修改",obj);
    }

    /**
     * 新增或修改
     * @param task
     * @return
     * @throws DaoException
     */
    public int insertOrUpdate(TableLog obj) throws DaoException {
        return getDao().saveOrUpdateModuleByIdExecuteNull("新增或修改",obj);
    }
    
    public int deleteByTaskId(String taskId) throws DaoException {
    	String sql = "DELETE FROM " + SI_TABLE("t_ddi_task_tab_log") + " WHERE task_id=?";
    	return getDao().delete("根据任务id删除任务表日志", sql, new Object[]{taskId});
    }

    /**
     * 获取表交换日志
     * @param taskId 任务
     * @param tableName 表名
     * @return
     * @throws DaoException
     */
    public TableLog getTableLogByTableName( String taskId, String tableName) throws DaoException {
        String sql = "select * from "+ SI_TABLE("t_ddi_task_tab_log")+" where task_id=? and table_name=?";
        return getDao().getModule("获取表交换日志",sql,TableLog.class,new Object[]{taskId,tableName});
    }

    /**
     * 获取表交换日志
     * @param taskId 任务
     * @return
     * @throws DaoException
     */
    public List<TableLog> listByTaskId(String taskId) throws DaoException {
        String sql = "select * from "+ SI_TABLE("t_ddi_task_tab_log")+" where task_id=?";
        return getDao().listModule("获取表交换日志",sql,TableLog.class,new Object[]{taskId});
    }
}
